<%@ tag language="java" pageEncoding="UTF-8" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<%@ attribute name="moduleCode" required="true" rtexprvalue="true"%>

<div id="userFavouritePanel"  ng-controller="UserFavouriteCtrl">   
  <div class="media" style="border-bottom: 1px dashed #EAEAEA;" ng-repeat="row in userFavourites" id="favouriteRow{{$index}}">
    <div class="media-body" ng-mouseover="showflag=1" ng-mouseleave="showflag=0" ng-init="showflag=0">
      <p class="media-heading " ><a href="${contextPath}{{row.recordUrl}}?id={{row.recordId}}">{{row.recordName}} </a>
      <span class="tools pull-right"  ng-show="showflag" >
        <a href="${contextPath }/oa/shareFile/open.do?id={{row.recordId }}" target="_blank" title="直接打开"><i class="icon-eye-open"></i></a>&nbsp;
        <a href="${contextPath }/oa/shareFile/download.do?id={{row.recordId }}" target="_blank" title="直接下载"><i class="icon-cloud-download"></i></a>&nbsp;
        <a title="<s:message code='userFavourite.func.remove'/>" ng-click="remove($index)"><i class="icon-remove"></i></a>                                                                             
      </span>      
      </p>
    </div>
  </div>  
</div>

<script type="text/javascript" src="${contextPath }/theme/default/js/angular.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  
  angular.element(document).ready(function() {  
    angular.bootstrap(document, [
            function ($httpProvider) {
              
              // Use x-www-form-urlencoded Content-Type
                $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
               
                /**
                 * The workhorse; converts an object to x-www-form-urlencoded serialization.
                 * @param {Object} obj
                 * @return {String}
                 */ 
                var param = function(obj) {
                  var query = '', name, value, fullSubName, subName, subValue, innerObj, i;
                    
                  for(name in obj) {
                    value = obj[name];
                      
                    if(value instanceof Array) {
                      for(i=0; i<value.length; ++i) {
                        subValue = value[i];
                        fullSubName = name + '[' + i + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                      }
                    }
                    else if(value instanceof Object) {
                      for(subName in value) {
                        subValue = value[subName];
                        fullSubName = name + '[' + subName + ']';
                        innerObj = {};
                        innerObj[fullSubName] = subValue;
                        query += param(innerObj) + '&';
                      }
                    }
                    else if(value !== undefined && value !== null)
                      query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&';
                  }
                    
                  return query.length ? query.substr(0, query.length - 1) : query;
                };
               
                // Override $http service's default transformRequest
                $httpProvider.defaults.transformRequest = [function(data) {
                  return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
                }];
              } 
        ]);  
      });
  
 
}); 

function UserFavouriteCtrl($scope, $http) {
  $scope.userFavourites = [];
  //init
  $http.get('${contextPath}/oa/shareFile/getUserFavourites.json?moduleCode=${moduleCode}', {
  }).success(function(data) {
      $scope.userFavourites = data.userFavourites; 
  }); 

  $scope.remove=function(index){
	  var userFavourite=$scope.userFavourites[index];
	  $http.get('${contextPath}/assistant/userFavourite/delete.json?id='+userFavourite.id, {
	  }).success(function(data){
		  $scope.userFavourites.splice(index,1);
	  } );
  }
}
</script> 